




//
//  ZNickAddSchoolLikeVC.m
//  ZQLearn
//
//  Created by macfeel on 2019/4/22.
//  Copyright © 2019 macfeel. All rights reserved.
//

#import "ZNickAddSchoolLikeVC.h"
//昵称  详细地址   学校    爱好
@interface ZNickAddSchoolLikeVC ()

///这个在修改电话时候 是电话号码输入框
@property (weak, nonatomic) IBOutlet UITextField *TextField;

@property (weak, nonatomic) IBOutlet UIButton *DoneBtn;

@property (weak, nonatomic) IBOutlet UIView *phoneBgView;

///这个是验证码输入框
@property (weak, nonatomic) IBOutlet UITextField *phoneTextField;

@property (weak, nonatomic) IBOutlet UIButton *authCodeBtn;


@end

@implementation ZNickAddSchoolLikeVC

- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.view.backgroundColor = kBackgroundColor;
    self.DoneBtn.layer.cornerRadius = 5.f;
    self.DoneBtn.layer.masksToBounds = YES;
    self.DoneBtn.backgroundColor = ThemeBlue;
    if (self.ttitle) {
        NSString *tt = [NSString stringWithFormat:@"修改%@",self.ttitle];
    [self.navigationItem setItemWithTitle:tt textColor:kNavigationTitleColor fontSize:18 itemType:center];
    }
    self.TextField.placeholder = self.ttitle;
    
    if ([self.ttitle isEqualToString:@"手机号"]) {
        self.phoneBgView.hidden = false;
        self.phoneTextField.hidden = false;
        self.authCodeBtn.hidden = false;
    }
    //p after loading the view from its nib.
}

//#define nickName @"nickName"
- (IBAction)doneBtnAction:(UIButton *)sender {
    [SVProgressHUD show];
    YYLog(@"完成");
    WeakStament(ws);
    NSDictionary *dic;
   NSString *userid =  [[NSUserDefaults standardUserDefaults]objectForKey:kUserId];
    if ([self.ttitle isEqualToString:@"昵称"]) {
        dic =@{@"id":[UserInfoSave shareInstance].ID?:userid,@"nickName":self.TextField.text?:@""};
        [ZNetworkService postRequestWithBaseUrl:kUpdateUserMsgUrl setParameters:dic success:^(id result) {
            YYLog(@"%@",result);
            if ([result[@"errorCode"]integerValue]==0) {
                [SVProgressHUD dismiss];
                NSDictionary *userDict = result[@"result"];
                [UserInfoSave shareInstance].nickName = userDict[@"nickName"];
                [[NSUserDefaults standardUserDefaults]setObject:@"nickName" forKey:userDict[@"nickName"]];
                [[NSUserDefaults standardUserDefaults]synchronize];
                [ws.navigationController popViewControllerAnimated:YES];
                [AFToast showText:@"修改成功"];
            }
        } fail:^(NSError *error) {
            YYLog(@"%@",error);
        } delegater:nil];
    }else if ([self.ttitle isEqualToString:@"详细地址"]){
        dic =@{@"id":[UserInfoSave shareInstance].ID?:userid,@"address":self.TextField.text?:@""};
        [ZNetworkService postRequestWithBaseUrl:kUpdateUserMsgUrl setParameters:dic success:^(id result) {
            YYLog(@"%@",result);
            if ([result[@"errorCode"]integerValue]==0) {
                NSDictionary *userDict = result[@"result"];
                [SVProgressHUD dismiss];
                [[NSUserDefaults standardUserDefaults]setObject:userDict[@"address"] forKey:@"address"];
                [[NSUserDefaults standardUserDefaults]synchronize];
                [UserInfoSave shareInstance].address = userDict[@"address"];
                [ws.navigationController popViewControllerAnimated:YES];
                [AFToast showText:@"修改成功"];
            }
        } fail:^(NSError *error) {
            YYLog(@"%@",error);
        } delegater:nil];
    }else if ([self.ttitle isEqualToString:@"学校"]){
        dic =@{@"id":[UserInfoSave shareInstance].ID?:userid,@"school":self.TextField.text?:@""};
        [ZNetworkService postRequestWithBaseUrl:kUpdateUserMsgUrl setParameters:dic success:^(id result) {
            YYLog(@"%@",result);
            if ([result[@"errorCode"]integerValue]==0) {
                [SVProgressHUD dismiss];
                NSDictionary *userDict = result[@"result"];
                [UserInfoSave shareInstance].school = userDict[@"school"];
                YYLog(@"%@",[UserInfoSave shareInstance].school);
                [[NSUserDefaults standardUserDefaults]setObject:userDict[@"school"] forKey:@"school"];
                [[NSUserDefaults standardUserDefaults]synchronize];
                [ws.navigationController popViewControllerAnimated:YES];
                [AFToast showText:@"修改成功"];
            }
        } fail:^(NSError *error) {
            YYLog(@"%@",error);
        } delegater:nil];
    }else if ([self.ttitle isEqualToString:@"爱好"]){
        dic =@{@"id":[UserInfoSave shareInstance].ID?:userid,@"hobby":self.TextField.text?:@""};
        [ZNetworkService postRequestWithBaseUrl:kUpdateUserMsgUrl setParameters:dic success:^(id result) {
            YYLog(@"%@",result);
            if ([result[@"errorCode"]integerValue]==0) {
                [SVProgressHUD dismiss];
                NSDictionary *userDict = result[@"result"];
                [UserInfoSave shareInstance].hobby = userDict[@"hobby"];
                [[NSUserDefaults standardUserDefaults]setObject:userDict[@"hobby"] forKey:@"hobby"];
                [[NSUserDefaults standardUserDefaults]synchronize];
                [ws.navigationController popViewControllerAnimated:YES];
                [AFToast showText:@"修改成功"];
            }
            
        } fail:^(NSError *error) {
            YYLog(@"%@",error);
            [SVProgressHUD dismiss];
        } delegater:nil];
        
    }else{
        ///手机号
        dic =@{@"id":[UserInfoSave shareInstance].ID?:userid,@"phone":self.TextField.text?:@"",@"codeRandom":self.phoneTextField.text?:@"",};
        [ZNetworkService postRequestWithBaseUrl:kupdatePhoneUrl setParameters:dic success:^(id result) {
            YYLog(@"%@",result);
            if ([result[@"errorCode"]integerValue]==0) {
                [SVProgressHUD dismiss];
                NSDictionary *userDict = result[@"result"];
                [UserInfoSave shareInstance].phone = userDict[@"phone"];
                [[NSUserDefaults standardUserDefaults]setObject:userDict[@"phone"] forKey:@"phone"];
                [[NSUserDefaults standardUserDefaults]synchronize];
                [ws.navigationController popViewControllerAnimated:YES];
                [AFToast showText:@"修改成功"];
            }
            
        } fail:^(NSError *error) {
            YYLog(@"%@",error);
            [SVProgressHUD dismiss];
        } delegater:nil];
        
    }

}




- (IBAction)authCodeAction:(UIButton *)sender {
//    YYLog(@"点击验证码");
    NSDictionary *dic =  @{@"phone":self.phoneTextField.text?:@"",};
    [ZNetworkService getRequestWithBaseUrl:kMsgCodeUrl setParameters:dic success:^(id result) {
        
        YYLog(@"%@",result);
        if ([result[@"errorCode"]integerValue]==0) {
            [AFToast showText:@"验证码发送成功"];
        }
        
    } fail:^(NSError *error) {
        
    } delegater:nil];
    
}



@end
